<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-tickets"></i>留言列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <!-- <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button> -->
                <el-date-picker v-model="startTime" type="datetime" class="handle-select" placeholder="开始日期" ></el-date-picker>
                <el-date-picker v-model="endTime" type="datetime"  class="handle-select" placeholder="结束日期"></el-date-picker>
                <el-input v-model="phone" placeholder="手机号" class="handle-input mr10"></el-input>
                <el-input v-model="name" placeholder="姓名" class="handle-input mr10"></el-input>
                <el-select v-model="isRead" placeholder="是否已读" class="handle-select mr10">
                    <el-option key="-1" label="已读" value="-1"></el-option>
                    <el-option key="1" label="未读" value="1"></el-option>
                </el-select>
                <el-button type="primary" icon="search" @click="search">搜索</el-button>
            </div>
            <el-table :data="leavingData" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
                <!-- <el-table-column type="selection" width="40"></el-table-column> -->
                <el-table-column prop="id" label="序号" sortable align="center">
                </el-table-column>
                <el-table-column prop="name" label="姓名" align="center">
                </el-table-column>
                <el-table-column prop="phone" label="手机号" align="center">
                </el-table-column>
                <el-table-column prop="companyName" label="公司名称" align="center">
                </el-table-column>
                <el-table-column prop="companyProfile" label="产品简介" align="center">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                </el-table-column>
                <el-table-column prop="isRead" label="是否已读" align="center" :formatter="isReadStatus">
                </el-table-column>
                <el-table-column label="操作" width="180" fixed="right" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" type="primary" @click="see(scope.$index, scope.row)">查看</el-button>
                        <el-button size="mini" type="danger" @click="del(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage4"
                    :page-sizes="[10, 15, 20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="50%" center>
            <div class="leaving">
                <p>姓名：{{detailsData.name}}</p>
                <p>手机号码：{{detailsData.phone}}</p>
                <p>公司名称：{{detailsData.companyName}}</p>
                <p>创建时间：{{detailsData.createTime}}</p>
                <p>活动介绍：{{detailsData.companyProfile}}</p>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="editVisible = false">关 闭</el-button>
            </span>
        </el-dialog>

        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { Message } from 'element-ui';
import { getLeavingData,delLeavingData } from '../../components/api/leaving.js';
    export default {
        // inject:['reload'],
        name: 'basetable',
        data() {
            return {
                tableData: [],
                multipleSelection: [],
                pageSize:10,
                pageNum:1,
                editVisible: false,
                delVisible: false,
                form: {
                    name: '',
                    date: '',
                    address: ''
                },
                leavingData:[],
                startTime:'',
                endTime:'',
                phone:'',
                name:'',
                isRead:'',
                idx: -1,
                currentPage4:1,
                total:0,
                delId:'',
                detailsData:{}
            }
        },
        created() {
            this.getData();
            // this.reload();
        },
        computed: {
            // data() {
            //     return this.tableData.filter((d) => {
            //         let is_del = false;
            //         console.log('============');
            //         console.log(this.del_list);
            //         for (let i = 0; i < this.del_list.length; i++) {
            //             if (d.name === this.del_list[i].name) {
            //                 is_del = true;
            //                 break;
            //             }
            //         }
            //         if (!is_del) {
            //             if (d.address.indexOf(this.select_cate) > -1 &&
            //                 (d.name.indexOf(this.select_word) > -1 ||
            //                     d.address.indexOf(this.select_word) > -1)
            //             ) {
            //                 return d;
            //             }
            //         }
            //     })
            // }
        },
        methods: {

            //选择列表数据条数
            handleSizeChange(val) {
                console.log('每页'+val+'条数');
                this.pageSize = val;
                this.getData();
            },
            //选择列表数据分页
            handleCurrentChange(val) {
                console.log('当前页'+val);
                this.pageNum = val;
                this.getData();
            },

            getData() {
                let router = this.$router;
                let params = {
                    endTime:this.endTime,
                    isRead:this.isRead,
                    name:this.name,
                    phone:this.phone,
                    startTime:this.startTime,
                    pageNum:this.pageNum,
                    pageSize:this.pageSize
                };

                //获取列表数据
               getLeavingData(params).then((res)=>{
                   if(res.status == 200){
                       this.leavingData = res.data.list;
                       this.total = res.data.total
                   }
                   console.log(res);
               }).catch((err)=>{
                   console.log(err);
               });
            },

            //列表搜索功能
            search() {
                this.getData();
            },

            isReadStatus(row,column){
                if(row.isRead == 0){
                    return '未读'
                }else{
                    return '已读'
                }
            },

            //查看活动详情
            see(index, row) {
                // this.idx = index;
                // this.delVisible = true;
                // this.delId = row.id;
               
                this.detailsData = row;
                this.editVisible = true;
                
            },
            //删除
            del(index,row){
                 this.idx = index;
                this.delId = row.id
                this.delVisible = true;
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 确定删除
            deleteRow(){
              let id = this.delId;
              let params = {
                  id:id
              };
              console.log(id);
              let that = this;
              delLeavingData(params).then((res)=>{
                  if(res.status == 200){
                      that.delVisible = false;
                      that.leavingData.splice(that.idx,1);
                      Message({
                          message:'删除成功',
                          type:'success'
                      });
                  }
              }).catch((err)=>{
                  Message.error(err.msg);
              });
                
            }
        }
    }

</script>

<style scoped>
    .add-user{
        float:right;
    }
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 190px;
    }

    .handle-input {
        width: 190px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .handle-botton{
        margin: 0 0 20px 80px;
    }
    .leaving{
        font-size: 17px;
        color: black;
        padding:0 200px;
    }
    .leaving>p{
        height:40px;
        line-height: 40px;
    }
</style>
